<?php

namespace Core\lib;

use Core\BeanFactory;
use Core\init\PhpRedisPool;

/**
 * Class RedisHelper
 * @method static string get(string $key)
 * @method static bool set(string $key, string $value)
 * @method static bool setex(string $key, int $ttl, string $value)
 * @method static array hGetAll(string $key)
 * @method static bool hMSet(string $key, array $array)
 * @method static bool hIncrBy(string $key, string $hashKey, int $value)
 * @method static int zAdd(string $key, float $score, string $value)
 */
class RedisHelper
{
    public static function __callStatic($name, $arguments)
    {
//        new \Redis();
        $pool = BeanFactory::getBean(PhpRedisPool::class);
        /**@var $pool PhpRedisPool* */
        $redis_obj = $pool->getConnect();
        try {
            if (!$redis_obj) return false;
            $redis = $redis_obj->redis;
            return $redis->$name(...$arguments);
        } catch (\Exception $exception) {
            echo $exception->getMessage() . PHP_EOL;
        } finally {
            if ($redis_obj) {
                $pool->close($redis_obj);
            }
        }
    }

}
